/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;
import java.awt.Color;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.plaf.basic.BasicBorders;
import javax.swing.table.DefaultTableModel;
/**
 *
 * @author Admin
 */
public class GUI extends JFrame {
    public JTextPane regIC, regPTR, regA, regB, regL, regMODE, regSI, regPI, regTI, regIOI, regTIMER, regCH1, regCH2, regCH3;
    public JButton stepButton, executeButton, restartProcessorButton, loadButton;
    public DefaultTableModel memmoryTableModel, virtualMemmoryTableModel;
    public JTable memmoryTable, virtualMemmoryTable;
    public JTextPane consolePane;
    public JTextField input;
    public Console console;
    
    public GUI() {
        //Toolkit tk = Toolkit.getDefaultToolkit();  
        //int xSize = ((int) tk.getScreenSize().getWidth())-100;  
        //int ySize = ((int) tk.getScreenSize().getHeight())-100;  
        this.setSize(1000, 700);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setResizable(false);
        this.setTitle("OS Project");
        //this.setUndecorated(true);
        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(null);
        
        JPanel registerPanel = new JPanel();
        registerPanel.setLayout(null);
        registerPanel.setBounds(10, 10, 200, 470);
        registerPanel.setBorder(new BevelBorder(1));
        registerPanel.setBackground(Color.gray);
        
        JPanel buttonsPanel = new JPanel();
        buttonsPanel.setLayout(null);
        buttonsPanel.setBounds(-2, this.getSize().height - 80, this.getWidth(), 50);
        buttonsPanel.setBorder(new BasicBorders.ButtonBorder(Color.gray, Color.gray, Color.gray, Color.gray));
        
        JPanel memmoriesPanel = new JPanel();
        memmoriesPanel.setLayout(null);
        memmoriesPanel.setBounds(250, 10, 850, 470);
        
        //TEXTAI
        JLabel textIC = new JLabel("IC:");
        JLabel textPTR = new JLabel("PTR:");
        JLabel textA = new JLabel("A:");
        JLabel textB = new JLabel("B:");
        JLabel textL = new JLabel("L:");
        JLabel textMODE = new JLabel("MODE:");
        JLabel textSI = new JLabel("SI:");
        JLabel textPI = new JLabel("PI:");
        JLabel textTI = new JLabel("TI:");
        JLabel textIOI = new JLabel("IOI:");
        JLabel textTIMER = new JLabel("TIMER:");
        JLabel textCH1 = new JLabel("CH1:");
        JLabel textCH2 = new JLabel("CH2:");
        JLabel textCH3 = new JLabel("CH3:");
        
        int textW = 75;
        int textH = 20;
        
        textIC.setBounds(10, 30, textW, textH);
        textPTR.setBounds(10, 60, textW, textH);
        textA.setBounds(10, 90, textW, textH);
        textB.setBounds(10, 120, textW, textH);
        textL.setBounds(10, 150, textW, textH);
        textMODE.setBounds(10, 180, textW, textH);
        textSI.setBounds(10, 210, textW, textH);
        textPI.setBounds(10, 240, textW, textH);
        textTI.setBounds(10, 270, textW, textH);
        textIOI.setBounds(10, 300, textW, textH);
        textTIMER.setBounds(10, 330, textW, textH);
        textCH1.setBounds(10, 360, textW, textH);
        textCH2.setBounds(10, 390, textW, textH);
        textCH3.setBounds(10, 420, textW, textH);
        
        registerPanel.add(textIC);
        registerPanel.add(textPTR);
        registerPanel.add(textA);
        registerPanel.add(textB);
        registerPanel.add(textL);
        registerPanel.add(textMODE);
        registerPanel.add(textSI);
        registerPanel.add(textPI);
        registerPanel.add(textTI);
        registerPanel.add(textIOI);
        registerPanel.add(textTIMER);
        registerPanel.add(textCH1);
        registerPanel.add(textCH2);
        registerPanel.add(textCH3);
        
        //REGISTRAI
        regIC = new JTextPane();
        regPTR = new JTextPane();
        regA = new JTextPane();
        regB = new JTextPane();
        regL = new JTextPane();
        regMODE = new JTextPane();
        regSI = new JTextPane();
        regPI = new JTextPane();
        regTI = new JTextPane();
        regIOI = new JTextPane();
        regTIMER = new JTextPane();
        regCH1 = new JTextPane();
        regCH2 = new JTextPane();
        regCH3 = new JTextPane();
        
        regIC.setEditable(false);
        regPTR.setEditable(false);
        regA.setEditable(false);
        regB.setEditable(false);
        regL.setEditable(false);
        regMODE.setEditable(false);
        regSI.setEditable(false);
        regPI.setEditable(false);
        regTI.setEditable(false);
        regIOI.setEditable(false);
        regTIMER.setEditable(false);
        regCH1.setEditable(false);
        regCH2.setEditable(false);
        regCH3.setEditable(false);
        
        int regW = 100;
        int regH = 20;
        int regStartX = 60;
        regIC.setBounds(regStartX, 30, regW, regH);
        regPTR.setBounds(regStartX, 60, regW, regH);
        regA.setBounds(regStartX, 90, regW, regH);
        regB.setBounds(regStartX, 120, regW, regH);
        regL.setBounds(regStartX, 150, regW, regH);
        regMODE.setBounds(regStartX, 180, regW, regH);
        regSI.setBounds(regStartX, 210, regW, regH);
        regPI.setBounds(regStartX, 240, regW, regH);
        regTI.setBounds(regStartX, 270, regW, regH);
        regIOI.setBounds(regStartX, 300, regW, regH);
        regTIMER.setBounds(regStartX, 330, regW, regH);
        regCH1.setBounds(regStartX, 360, regW, regH);
        regCH2.setBounds(regStartX, 390, regW, regH);
        regCH3.setBounds(regStartX, 420, regW, regH);
        
        registerPanel.add(regIC);
        registerPanel.add(regPTR);
        registerPanel.add(regA);
        registerPanel.add(regB);
        registerPanel.add(regL);
        registerPanel.add(regMODE);
        registerPanel.add(regSI);
        registerPanel.add(regPI);
        registerPanel.add(regTI);
        registerPanel.add(regIOI);
        registerPanel.add(regTIMER);
        registerPanel.add(regCH1);
        registerPanel.add(regCH2);
        registerPanel.add(regCH3);
        
        //MYGTUKAI
        stepButton = new JButton();
        stepButton.setText("Next step");
        stepButton.setBounds(10, 10, 100, 20);
        
        executeButton = new JButton();
        executeButton.setText("Execute program");
        executeButton.setBounds(150, 10, 150, 20);
        
        restartProcessorButton = new JButton();
        restartProcessorButton.setText("Restart processor");
        restartProcessorButton.setBounds(buttonsPanel.getWidth()-340, 10, 150, 20);
        restartProcessorButton.setVisible(false);
        
        loadButton = new JButton();
        loadButton.setText("Load program");
        loadButton.setBounds(buttonsPanel.getWidth()-160, 10, 150, 20);
        
        buttonsPanel.add(stepButton);
        buttonsPanel.add(executeButton);
        buttonsPanel.add(loadButton);
        buttonsPanel.add(restartProcessorButton);
        
        mainPanel.add(registerPanel);
        mainPanel.add(buttonsPanel);
        
        //ATMINTIS
        JLabel textMem = new JLabel("Memmory");
        textMem.setBounds(0, 0, 300, 15);
        memmoriesPanel.add(textMem);
        
        JScrollPane scrollPaneM = new JScrollPane();
        scrollPaneM.setBounds(0, 20, 300, 450);
        Object[][] rowData = {};
        Object[] columnsData = {"ADDRESS", "BYTE[0]", "BYTE[1]", "BYTE[2]", "BYTE[3]"};
        memmoryTableModel = new DefaultTableModel(rowData, columnsData);
        
        memmoryTable = new JTable(memmoryTableModel) {
            public boolean isCellEditable(int row, int column) {                
                         return false;               
            };
         };

        scrollPaneM.setViewportView(memmoryTable);
        memmoriesPanel.add(scrollPaneM);
        
        //Virtuali atmintis  
        JLabel textVirtMem = new JLabel("Virtual memmory");
        textVirtMem.setBounds(330, 0, 300, 15);
        memmoriesPanel.add(textVirtMem);
        
        JScrollPane scrollPaneVM = new JScrollPane();
        scrollPaneVM.setBounds(330, 20, 300, 450);
        virtualMemmoryTableModel = new DefaultTableModel(rowData, columnsData);
        
        virtualMemmoryTable = new JTable(virtualMemmoryTableModel) {
            public boolean isCellEditable(int row, int column) {                
                         return false;               
            };
         };

        scrollPaneVM.setViewportView(virtualMemmoryTable);
        memmoriesPanel.add(scrollPaneVM);
        
        mainPanel.add(memmoriesPanel);
        
        //KONSOLE
        JScrollPane scrollPaneConsole = new JScrollPane();
        scrollPaneConsole.setBounds(10, 490, 975, 100);
        
        consolePane = new JTextPane();
        consolePane.setBackground(Color.black);
        consolePane.setCaretColor(Color.white);
        consolePane.setDisabledTextColor(Color.white);
        consolePane.setForeground(Color.white);
        consolePane.setEditable(true);
        
        scrollPaneConsole.setViewportView(consolePane);
        mainPanel.add(scrollPaneConsole);
        
        input = new JTextField();
        input.setBounds(10, 590, 975, 20);
        mainPanel.add(input);
        
        this.add(mainPanel);
        console = new Console(this);
    }
}
